package com.service.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.service.common.core.domain.entity.ScoreList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.service.common.annotation.Log;
import com.service.common.core.controller.BaseController;
import com.service.common.core.domain.AjaxResult;
import com.service.common.enums.BusinessType;
import com.service.system.service.IScoreListService;
import com.service.common.utils.poi.ExcelUtil;
import com.service.common.core.page.TableDataInfo;

/**
 * 分数信息Controller
 *
 * @author service
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/system/scoreList")
public class ScoreListController extends BaseController
{
    @Autowired
    private IScoreListService scoreListService;

    /**
     * 查询分数信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScoreList scoreList)
    {
        startPage();
        List<ScoreList> list = scoreListService.selectScoreListList(scoreList);
        return getDataTable(list);
    }

    /**
     * 导出分数信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:export')")
    @Log(title = "分数信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoreList scoreList)
    {
        List<ScoreList> list = scoreListService.selectScoreListList(scoreList);
        ExcelUtil<ScoreList> util = new ExcelUtil<ScoreList>(ScoreList.class);
        util.exportExcel(response, list, "分数信息数据");
    }

    /**
     * 获取分数信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scoreListService.selectScoreListById(id));
    }

    /**
     * 新增分数信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:add')")
    @Log(title = "分数信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoreList scoreList)
    {
        return toAjax(scoreListService.insertScoreList(scoreList));
    }

    /**
     * 修改分数信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "分数信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoreList scoreList)
    {
        return toAjax(scoreListService.updateScoreList(scoreList));
    }

    /**
     * 删除分数信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:remove')")
    @Log(title = "分数信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scoreListService.deleteScoreListByIds(ids));
    }

    @GetMapping(value = "/data/{id}")
    public AjaxResult getStudentScoreInfo(@PathVariable("id") String id)
    {
        List<ScoreList> scoreLists = scoreListService.selectScoreInfo(id);
        if (scoreLists == null) {
            return error("数据异常");
        }
        return success(scoreLists);
    }
}
